<template>
	<view>
		<view style="">
			<u-search placeholder="车牌号" v-model="form.text" @search="getData" @click="getData"></u-search>
		</view>
		<view v-if="data">
			<u-cell-group>
				<u-cell-item v-for="item in data" @click="selectItem=item;show=true">
					<view slot="right-icon" style="width: 150rpx;">
						<text>
							{{item.car_num}}
						</text>
					</view>
					<view slot="label">
						<text>{{item.myType.cxmc}}</text>
					</view>
					<view slot="title">
						<view style="display: flex;justify-content: start;">
							<view>
								<text>{{item.myType.qdfs}}</text>
								<text>/</text>
							</view>
							<view>
								<text>{{item.myType.zwgs}}座</text>
								<text>/</text>
							</view>

							<view>
								<text>{{item.myType.rlxs}}</text>
								<text>/</text>
							</view>
							<view>
								<text>{{item.myType.rybh}}</text>
							</view>
						</view>
					</view>
				</u-cell-item>
			</u-cell-group>
		</view>
		<u-modal v-model="show" @confirm="replaceCar" :show-cancel-button="true">
			<view class="slot-content" style="padding: 30rpx;">
				<text>确定选择 【</text>
				<text>{{selectItem.car_num}} </text>
				<text>{{selectItem.myType.cxmc}}】 </text>
				<text>吗？ </text>
			</view>
		</u-modal>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				selectItem: null,
				show: false,
				car_num: '',
				data: null,
				orders: null,
				form: {
					text: '',

				}
			}
		},
		mounted() {
			this.getData();
		},
		onLoad(options) {
			if (options.data) {
				this.orders = JSON.parse(decodeURIComponent(options.data));
			}
		},
		onPullDownRefresh() {
			this.refresherpulling();
		},
		onReachBottom() {
			console.log(this.count);
			if (this.count == 0) {
				this.$refs.uToast.show({
					title: '到底了',
					type: "warning"
				});
				return;
			}
			this.scrolltolower();
		},
		methods: {
			replaceCar() {
				var that = this;
				var form = {};
				form.before_car_id = this.selectItem.car_id;
				form.car_pool_id = this.selectItem.car_pool_id;
				form.car_share_id = this.selectItem.car_share_id;
				form.car_borrow_id = this.selectItem.car_borrow_id;
				form.order_id = this.orders.orders_id;
				that.$http.post('/orders/replaceCar',form, (res) => {
					if (res.data.success) {
						that.data = res.data.result.list;
						that.$refs.uToast.show({
							title: '更换成功',
							type: "success"
						});
						uni.$emit("getOrdersInfo", that.data);
						uni.navigateBack();
					} else {
						that.refs.myModal.show('请求失败', res.data.result.message);
					}
				});
			},
			getData() {
				var that = this;
				
				that.$http.post('/carPool/ListByEntity', this.form, (res) => {
					if (res.data.success) {
						that.data = res.data.result.list;
					} else {
						that.refs.myModal.show('请求失败', res.data.result.message);
					}
				});
			},
			refresherpulling(e) {
				this.form.page = 1;
				this.refresher = true;
				this.data = [];
				this.getData();
			},
			scrolltolower(e) {
				this.form.page++;
				this.getData();
			},
		}
	}
</script>

<style>

</style>